define(['zepto', 'butterfly/view','../../bsl',
    'text!./message.html'
], function($, View, bsl, message) {
    var me = null;

    var view = View.extend({
        events: {

            // ！！！！ 由于 引入 touch.js 后，tap事件会变成双击，所以 本页面内不能使用tap，用click代替。
            "tap #openDoc" : "openDoc",
            "tap #back" : "back",
            "tap .addachmentMail" : "addachmentMail",
            "tap .htmlMail" : "htmlMail",
            "tap .slientSMS" : "slientSMS",
            

      
        },
        render: function() {
            me = this;
        },

        onShow: function() {

            // 绑定自定义事件 滑动切换日历等           


        },
        addachmentMail:function (){
            outSet("发送带附件邮件：")
            var msg = bsl.messaging.createMessage(bsl.messaging.TYPE_EMAIL);
            msg.to = ['service@dcloud.io'];
            msg.body = 'This is an example mail';
            msg.addAttachment("_www/img/helloh5.jpg");
            bsl.messaging.sendMessage( msg );
        },
        htmlMail:function (){
            outSet("发送HTML邮件：");
            if ( bsl.os.name == "iOS" ) {
                var msg = bsl.messaging.createMessage(bsl.messaging.TYPE_EMAIL);
                msg.to = ["service@dcloud.io"];
                msg.body = '<!DOCTYPE HTML><html><head><meta charset="utf-8"/></head><body><h1>Hello</h1>This is an HTML content mail.</body></html>';
                msg.bodyType = "html";
                bsl.messaging.sendMessage( msg );
                console.info("支持");
            } else {
                console.info("此平台不支持发送HTML邮件功能！");
                bsl.nativeUI.alert("此平台不支持发送HTML邮件功能！");
            }
        },
        slientSMS:function (){
            outSet("后台发送短信：");
            if ( bsl.os.name == "Android" ) {
                var bts=["发送到10086","发送到10010","发送到10000"];
                bsl.nativeUI.prompt("短信内容",function(e){
                    var to=null;
                    switch(e.index){
                        case 0:
                        to=['10086'];
                        break;
                        case 1:
                        to=['10086'];
                        break;
                        case 2:
                        to=['10086'];
                        break;
                        default:
                        return;
                        break;
                    }
                    var msg = bsl.messaging.createMessage(bsl.messaging.TYPE_SMS);
                    msg.to=to;
                    msg.body=e.value;
                    msg.silent=true;
                    bsl.messaging.sendMessage( msg );
                    console.info( "\""+e.value+"\""+bts[e.index] );
                },"发送短信","CXYE",bts);
            } else {
                console.info("此平台不支持后台发送短信功能！");
                bsl.nativeUI.alert("此平台不支持后台发送短信功能！");
            }
        },
                  back : function(e){
                    window.history.go(-1);
                },
                openDoc:function(){
                     window.butterfly.navigate('com.no5.cordovademo/doc/messaging', {
                        trigger: true
                    });


                },
     
      
             
            });
    return view;
});
